import 'package:flutter/material.dart';

// 外边框样式
class InwardRoundedClipper extends CustomClipper<Path> {
  @override
  Path getClip(Size size) {
    const double radius = 10.0; // 圆弧半径
    final path = Path();

    // 从顶部凹槽的右侧起点 (radius, 0)
    path.moveTo(radius, 0);

    // 绘制顶部直线，直到右上角凹槽的左侧
    path.lineTo(size.width - radius, 0);

    // 绘制右上角向内凹槽
    path.arcToPoint(
      Offset(size.width, radius),
      radius: const Radius.circular(radius),
      clockwise: false,
    );

    // 绘制右侧直线
    path.lineTo(size.width, size.height - radius);

    // 绘制右下角向内凹槽
    path.arcToPoint(
      Offset(size.width - radius, size.height),
      radius: const Radius.circular(radius),
      clockwise: false,
    );

    // 绘制底部直线
    path.lineTo(radius, size.height);

    // 绘制左下角向内凹槽
    path.arcToPoint(
      Offset(0, size.height - radius),
      radius: const Radius.circular(radius),
      clockwise: false,
    );

    // 绘制左侧直线
    path.lineTo(0, radius);

    // 绘制左上角向内凹槽
    path.arcToPoint(
      const Offset(radius, 0),
      radius: const Radius.circular(radius),
      clockwise: false,
    );

    path.close(); // 闭合路径
    return path;
  }

  @override
  bool shouldReclip(CustomClipper<Path> oldClipper) => false;
}

// 内框样式
class TicketWithBorder extends StatelessWidget {
  final Color borderColor;
  const TicketWithBorder({super.key, this.borderColor = Colors.white});

  @override
  Widget build(BuildContext context) {
    return CustomPaint(
      painter: BorderPainter(borderColor),
    );
  }
}

class BorderPainter extends CustomPainter {
  final Color borderColor;
  BorderPainter(this.borderColor);
  @override
  void paint(Canvas canvas, Size size) {
    const double radius = 10.0; // 圆角半径
    const double borderWidth = 1.0; // 边框宽度

    final Paint borderPaint = Paint()
      ..color = borderColor
      ..style = PaintingStyle.stroke
      ..strokeWidth = borderWidth;

    final Path path = Path();

    // 从顶部凹槽的右侧起点 (radius, 0)
    path.moveTo(radius, 0);

    // 绘制顶部直线，直到右上角凹槽的左侧
    path.lineTo(size.width - radius, 0);

    // 绘制右上角向内凹槽
    path.arcToPoint(
      Offset(size.width, radius),
      radius: const Radius.circular(radius),
      clockwise: false,
    );

    // 绘制右侧直线
    path.lineTo(size.width, size.height - radius);

    // 绘制右下角向内凹槽
    path.arcToPoint(
      Offset(size.width - radius, size.height),
      radius: const Radius.circular(radius),
      clockwise: false,
    );

    // 绘制底部直线
    path.lineTo(radius, size.height);

    // 绘制左下角向内凹槽
    path.arcToPoint(
      Offset(0, size.height - radius),
      radius: const Radius.circular(radius),
      clockwise: false,
    );

    // 绘制左侧直线
    path.lineTo(0, radius);

    // 绘制左上角向内凹槽
    path.arcToPoint(
      const Offset(radius, 0),
      radius: const Radius.circular(radius),
      clockwise: false,
    );

    path.close(); // 闭合路径

    // 绘制路径作为边框
    canvas.drawPath(path, borderPaint);
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
}
